package niuke;

/**
 * description:
 * author:张腾
 * date:2021-07-12
 */

import java.util.Arrays;

/**
 * 给定一个无序数组arr，找到数组中未出现的最小正整数
 * 例如arr = [-1, 2, 3, 4]。返回1
 * arr = [1, 2, 3, 4]。返回5
 * [要求]
 * 时间复杂度为O(n)O(n)，空间复杂度为O(1)O(1)
 */
public class NC30 {
    public int minNumberdisappered (int[] arr) {
        // write code here
        Arrays.sort(arr);
        int target = 1;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]<=0) continue;
            else if (arr[i]==target) target++;
            else if (arr[i]>target) break;
        }
        return target;
    }
}
